#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 20005;
int n, father;//重心的父亲
vector <int> g[N];
int size[N];//每个点子树的大小
bool vis[N];
int ai = 0x3f3f3f3f, ans = -1;
void dfs (int u, int x) {
	bool flag = true;
	size[x] = 1;
	for (unsigned i = 0; i < g[x].size(); i++){
		int v = g[x][i];
		if (!vis[v]) {
			vis[v] = 1;
			dfs (x, v);
			size[x] += size[v];
			if (size[v] > n / 2) {
				flag = false;
			}
		}
	}
	if (n - size[x] > n / 2) {
		flag = false;
	}
	if (flag && x < ai) {
		ai = x;
		father = u;
	}
}
int main() {
	int t;
	scanf ("%d", &t);
	for (int j = 1; j <= t; j++) {
		scanf ("%d", &n);
		ans = -1;
		ai = 0x3f3f3f3f;
		memset (vis, 0, sizeof(vis));
		memset (size, 0, sizeof(size));
		for (int i = 0; i < N; i++) {
			g[i].clear();
		}
		int x, y;
		for (int i = 1; i < n; i++) {
			scanf ("%d%d", &x, &y);
			g[x].push_back(y);
			g[y].push_back(x);
		}
		vis[1] = 1;
		dfs (-1, 1);
		for (unsigned i = 0; i < g[ai].size(); i++) {
			if (g[ai][i] == father) {
				ans = max (ans, n - size[ai]);
			} else {
				ans = max (ans, size[g[ai][i]]);
			}
		}
		printf ("%d %d\n", ai, ans);
	}
	return 0;
}